1. Field of the Invention
The invention relates to a system, method an program product for optimising computer software by the technique of procedure cloning. The term “program product” here means a body of computer code stored by a machine readable storage medium such as a CD Rom or one or more floppy discs, or made available for downloading from a remote computer site. The computer code may be integrated within a compiler and be operable for optimising object or intermediate code formed by the compiler.
2. Related Art
A computer program may comprise a call statement for calling a procedure, function or sub-routine (each referred to hereinafter as a “procedure”) included in the program itself or provided in a separate library of procedures or as a respective separate object file. Often a particular procedure is called several or even many times by statements at respective different “call-sites” within the program.
In most cases, the procedures will be provided with parameters or arguments supplied by the call site.
In order to optimise a computer program under development, the technique known as procedure cloning may be useful. This known technique involves the creation of copies of procedures with specialised values of parameters passed to them at a specific site. For example, given a procedure
void proc(int a, int b);
and a call-site that calls this procedure as:
proc(10,b);
the procedure might be cloned as:
void proc—1(int b)
where the procedure body is re-computed by setting a=10 at the beginning of the procedure, and propagating this value in the procedure body. The original call then will be replaced as a call to this cloned procedure:
proc—1(b)
The advantages of procedure cloning is that the cloned specialised procedure may be more efficient and sometimes it may be integrated into the computer code at the relevant call site. In some cases, the specialised procedure may turn out to be a NULL item which is never executed at that call site or it may return a parameter which is a constant. Then, of course, the call statement could be removed.
Another technique useful for software optimisation in conjunction with procedure cloning relates to call graphs. In computer science a graph consists of a collection of vertices or “nodes” joined by lines called ‘edges’. A graph may be used to represent many different situations or problems. A control flow graph is a way of representing the dependencies between items of control flow code in a computer program and code branches to which program flow is directed by the control flow code. Such a graph is formed with a series of branching nodes representing items of control flow code and further nodes for the code branches. Arrows are drawn identifying “edges” or the interfaces between the nodes. The call parameters, i.e. the variables passed to the code branches by the control flow code are often also shown adjacent the arrows. U.S. Pat. No. 5,812,855 to Hiranandani et al discloses a system and method for use in the inter-procedural optimisation of computer software where such call graphs or control flow graphs are used. As disclosed by Hiranandani et al, the use of control flow graphs in conjunction with procedure cloning can assist optimising processes. In particular, the construction of a control flow graph can help to identify a procedure which it would be useful to clone. Thus, in Hiranandani et al, cloning is done by reference to whether a particular node receives calls from an “unknown” call site, i.e. whether the node may be called by a previously compiled item of object code and which is hence unamenable to optimisation.
Even so, it remains the case that procedure calls present a difficult barrier for accurate analysis and optimisation of code. Without care, much information may be lost at a call-site regarding the possible behaviour and values of variables and the object of the invention is to provide a means for ensuring that such loss is minimized whilst enhancing the possibility of creating and using specialised versions of procedure bodies.